package com.ruoyi.basedata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.WfzGybaseunit;
import com.ruoyi.basedata.service.IWfzGybaseunitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 盖亚组织Controller
 * 
 * @author xiefeng
 * @date 2022-12-06
 */
@RestController
@RequestMapping("/basedata/gybaseunit")
public class WfzGybaseunitController extends BaseController
{
    @Autowired
    private IWfzGybaseunitService wfzGybaseunitService;

    /**
     * 查询盖亚组织列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:gybaseunit:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfzGybaseunit wfzGybaseunit)
    {
        startPage();
        List<WfzGybaseunit> list = wfzGybaseunitService.selectWfzGybaseunitList(wfzGybaseunit);
        return getDataTable(list);
    }

    /**
     * 导出盖亚组织列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:gybaseunit:export')")
    @Log(title = "盖亚组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfzGybaseunit wfzGybaseunit)
    {
        List<WfzGybaseunit> list = wfzGybaseunitService.selectWfzGybaseunitList(wfzGybaseunit);
        ExcelUtil<WfzGybaseunit> util = new ExcelUtil<WfzGybaseunit>(WfzGybaseunit.class);
        util.exportExcel(response, list, "盖亚组织数据");
    }

    /**
     * 导入数据管理列表
     */
    @Log(title = "数据管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<WfzGybaseunit> util = new ExcelUtil<WfzGybaseunit>(WfzGybaseunit.class);
        List<WfzGybaseunit> dataManagementList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = wfzGybaseunitService.importData(dataManagementList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<WfzGybaseunit> util = new ExcelUtil<WfzGybaseunit>(WfzGybaseunit.class);
        util.importTemplateExcel(response,"案卷数据");
    }


    /**
     * 获取盖亚组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:gybaseunit:query')")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") Long fid)
    {
        return success(wfzGybaseunitService.selectWfzGybaseunitByFid(fid));
    }

    /**
     * 新增盖亚组织
     */
    @PreAuthorize("@ss.hasPermi('basedata:gybaseunit:add')")
    @Log(title = "盖亚组织", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfzGybaseunit wfzGybaseunit)
    {
        //获取当前登录用户的用户名，并且设置到制单人属性中
        wfzGybaseunit.setFcreator(getUsername());
        //获取当前登录用户的用户名，并且设置到修改人属性中
        wfzGybaseunit.setFlastupdateuser(getUsername());
        return toAjax(wfzGybaseunitService.insertWfzGybaseunit(wfzGybaseunit));
    }

    /**
     * 修改盖亚组织
     */
    @PreAuthorize("@ss.hasPermi('basedata:gybaseunit:edit')")
    @Log(title = "盖亚组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfzGybaseunit wfzGybaseunit)
    {
        //获取当前登录用户的用户名，并且设置到修改人属性中
        wfzGybaseunit.setFlastupdateuser(getUsername());
        return toAjax(wfzGybaseunitService.updateWfzGybaseunit(wfzGybaseunit));
    }

    /**
     * 删除盖亚组织
     */
    @PreAuthorize("@ss.hasPermi('basedata:gybaseunit:remove')")
    @Log(title = "盖亚组织", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable Long[] fids)
    {
        return toAjax(wfzGybaseunitService.deleteWfzGybaseunitByFids(fids));
    }
}
